home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char SccsId[]= "@(#)buf_stuff.c V1.13 3/22/95";
- #endif
-
- /*
- | file name - buf_stuff.c
- |===================================================================
- |
- | This program is an example of how you might get data into your
- | views without using the data source facility. The method
- | accomplishes its task by using the buffers contained in the
- | data source variables (dsv) as a source for the data. The
- | data is placed into these buffers rather than having to be
- | gathered by the DataViews routines TviReadData or
- | TdlReadData. This process is loosely referred to as
- | "stuffing the data source buffers".
- |
- | Typing a <q|Q> or the right mouse button will exit the program.
- |
- |===================================================================
- */
- #include <windows.h>
-
- /* DV-Tools header files */
- #include "std.h" /* <stdio.h> etc., scalar & macro definitions */
- #include "dvstd.h" /* public types & constants */
- #include "dvtools.h" /* constants used by T routines */
- #include "dvGR.h" /* constants used by window mgt & GR routines */
- #include "VOstd.h" /* constants used by VO & VOob routines */
- #include "Tfundecl.h" /* T routines (screens, drawports & views) */
- #include "VOfundecl.h" /* VO routines (objects) */
-
- /* Constants */
- #define DVPATH (char *)NULL
- #define DISPFORMS_STB (char *)NULL
- #define DVDEVICE (char *)NULL
- #define DVCOLORTABLE (char *)NULL
- #define VIEW_NAME "buffer.v"
- #define SCREEN_VIEWPORT (RECTANGLE *)NULL
- #define DRAWING_VIEWPORT (RECTANGLE *)NULL
-
- /*
- * Declare the pointers to be used for stuffing the buffers.
- */
- LOCAL char *TextBufPtr; /* data buffer of dsv named Text Var */
- LOCAL float *FloatBufPtr; /* data buffer of dsv named Float Var */
- LOCAL int counter = 0; /* init counter used in UpdateData routine */
-
- /* Local forward function declarations */
- LOCAL ADDRESS GetDsvBuffers V_P_ ((DATASOURCE ds, DSVAR dsvar,
- ADDRESS argblock));
- LOCAL void UpdateData V_P_ ((void));
-
-
- /*
- * MAIN PROGRAM
- */
- int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow )
- {
- INT argc = 0;
- CHAR **argv;
-
- /*
- * program arguments
- * argv[1] - display device (default is DVDEVICE)
- */
-
- /* Define & initialize device name and view filename */
- char *device_name = DVDEVICE; /* default device name */
- char *view_name = VIEW_NAME; /* default view name */
-
- /* Define display variables */
- OBJECT screen; /* display device, the window */
- DRAWPORT drawport; /* how & where to display picture, picture frame */
- VIEW view; /* picture representation of the view file */
-
- /* Control loop variables */
- OBJECT location; /* the event representation */
-
- /* Other variables */
- DATASOURCELIST dsl; /* list of data sources */
- int Quit = NO; /* flag to quit program */
-
- /*-----------------
- * Initialization
- *
- * TInit: perform the initialization of DV-Tools
- * TInit reads your configuration file and any
- * environment variables or logical names set.
- */
- make_argv(&argc,&argv,GetCommandLine());
- TInit( DVPATH, DISPFORMS_STB );
-
- /*
- * TscOpenSet: opens a device as a screen object using
- * specified attributes
- */
- if (argc > 1)
- device_name = argv[1];
- screen = TscOpenSet (device_name, DVCOLORTABLE,
- V_X_EXPOSURE_BLOCK, YES,
- V_ACTIVE_CURSOR, V_END_OF_LIST);
- if (!screen)
- {
- printf ("Must specify device on command line or");
- printf (" in DataViews configuration file.\n");
- S_EXIT (EXIT_ERR);
- }
-
- /*
- * VOscWinEventMask: sets the screen's window event mask
- */
- VOscWinEventMask ((ULONG) V_KEYPRESS | V_BUTTONPRESS | V_EXPOSE | V_RESIZE,
- (ULONG) 0);
-
- /*
- * TviLoad: Load a view in from a file,
- * user supplied view or default view of buffer.v
- */
- view = TviLoad (view_name);
- if (!view)
- {
- printf ("Could not load view from file ");
- printf ("%s.\n", view_name);
- S_EXIT (EXIT_ERR);
- }
-
- /*
- * TviGetDataSourceList: Gets a view's data source list
- * TdlForEachVar: Traverses all data source variables
- *
- * Traverse all data source variables found in the view's
- * data source list and call the function GetDsvBuffers
- * for each one.
- */
- dsl = TviGetDataSourceList (view);
- TdlForEachVar (dsl, GetDsvBuffers, (ADDRESS) NULL);
-
- /*
- * TdpCreate: Create a drawport.
- * The drawport is attached to the screen object
- * specified while view specifies the view to be
- * displayed on the screen.
- *
- * UpdateData: Update data source buffers used by dynamic
- * objects in view.
- */
- drawport = TdpCreate (screen, view, SCREEN_VIEWPORT, DRAWING_VIEWPORT);
- UpdateData ();
-
- /*
- * TscErase: Erase the entire screen in the default
- * background color
- * TdpDraw: Draw the contents of the drawport
- */
- TscErase (screen);
- TdpDraw (drawport);
-
- /*--------------------
- * Control loop
- *
- * Poll the event queue for locator events. If the key
- * represents the character 'q' or 'Q' or the right
- * mouse button then quit the program. Meanwhile,
- * continue to update the data source buffers and draw the
- * next iteration of the drawport.
- */
- FOREVER
- {
- /*
- * VOloWinEventPoll: Poll for the next window event.
- * The polling mode used is V_WAIT.
- * Therefore, VOloWinEventPoll does not
- * return until a masked event is
- * generated. V_WAIT always produces
- * a valid location object.
- */
- location = VOloWinEventPoll (V_WAIT);
-
- /*
- * VOloType: returns the type of event. These types
- * match event types specified in VOscWinEventMask.
- */
- switch (VOloType (location))
- {
-
- case V_RESIZE:
- /*
- * The window size has been changed.
- * TscReset: Resets all screen drawports after
- * window resizing
- */
- TscReset (screen);
- break;
-
- case V_EXPOSE:
- /*
- * VOloRegion: Returns a rectangle representing the
- * exposed region on the screen.
- * TscRedraw: After erasing, redraws all the drawports
- * in the screen.
- * A portion of the window has been exposed and needs
- * to be redrawn.
- */
- TscRedraw (screen, VOloRegion (location));
- break;
-
- case V_KEYPRESS:
- /*
- * Check key selected.
- * VOloKeySym: Returns the key symbol value of the
- * location object
- *
- * If the key symbol represents the characters 'q'
- * or 'Q' then quit the program.
- */
- switch (VOloKeySym (location))
- {
- case 'q':
- case 'Q':
- Quit = YES;
- break;
-
- default:
- /*
- * TdpDrawNext: Update all dynamic objects within a
- * drawport's view.
- * Update internal data buffers and draw next iteration
- */
- UpdateData ();
- TdpDrawNext (drawport);
- break;
- }
- break;
-
- case V_BUTTONPRESS:
- /*
- * VOloButton: Returns the button that was pressed
- *
- * The right mouse button exits the program.
- */
- if (VOloButton (location) == 3)
- Quit = YES;
- else
- {
- /*
- * TdpDrawNext: Update all dynamic objects within a
- * drawport's view.
- * Update internal data buffers and draw next iteration
- */
- UpdateData ();
- TdpDrawNext (drawport);
- }
- break;
-
- default:
- break;
- }
-
- /* exit the program */
- if (Quit == YES)
- break;
- }
-
- /*--------------------
- * Termination
- *
- * TscErase: Erase the entire screen in the default
- * background color
- * TdpDestroy: Destroy the drawport,
- * TviDestroy: Destroy the view, freeing the allocated memory
- * TscCloseCurrentScreen: Close the current display screen
- * TTerminate: Perform the clean-up for DV-Tools
- */
- TscErase (screen);
- TdpDestroy (drawport);
- TviDestroy (view);
- TscCloseCurrentScreen ();
- TTerminate ();
- return EXIT_OK;
- }
-
-
- /*
- *----------------
- * GetDsvBuffers -- get the address of the data buffers
- * pointed to by the data source variable. Store the
- * address of this data buffer which will be used
- * later when updating dynamic objects.
- */
- /*ARGSUSED*/
- LOCAL ADDRESS
- GetDsvBuffers (ds, dsvar, argblock)
- DATASOURCE ds;
- DSVAR dsvar;
- ADDRESS argblock;
- {
- char *name; /* data source variable name */
-
- /*
- * TdsvGetName: Gets the name of a data source variable
- *
- * Obtain the address of the data source variable's
- * data buffer. The application will update the
- * contents of the data buffer pointed to by this
- * address. This is referred to as stuffing the
- * buffers.
- */
- name = TdsvGetName (dsvar);
- if (strcmp (name, "Text Var") == 0)
- TextBufPtr = TdsvGetBuffer (dsvar);
- else if (strcmp (name, "Float Var") == 0)
- FloatBufPtr = (float *) TdsvGetBuffer (dsvar);
-
- return V_CONTINUE_TRAVERSAL;
- }
-
-
- /*
- *-------------
- * UpdateData -- updates the values in the buffers of the
- * dynamic elements of the view.
- */
- LOCAL void
- UpdateData ()
- {
- LOCAL char *mycharbuf[] =
- {
- "1st time",
- "2nd time",
- "3rd time",
- "4th time",
- "5th time",
- "6th time",
- "7th time",
- "8th time",
- "9th time",
- "10th time"
- };
-
- /*
- * Increment the counter by one, copy the character string based
- * on the counter value to the data source buffer TextBufPtr.
- */
- if (++counter > 10)
- counter = 1;
-
- strcpy (TextBufPtr, mycharbuf[counter-1]);
-
- /*
- * Set the data source variable FloatBufPtr by incrementing its
- * current value by .1. Reset FloatBufPtr to zero when the
- * the counter has been reset.
- */
- if (counter == 1)
- *FloatBufPtr = 0.0;
- else
- *FloatBufPtr += 0.1;
- }
-